package com.coisini.config;

import com.aliyuncs.OssAcsRequest;
import com.coisini.properties.AliOssProperties;
import com.coisini.utils.AliOssUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 配置类，用于创建AliOssUtil对象
 */
@Configuration //配置类
@Slf4j
public class OssConfiguration {


    @Bean // 使其成为IOC容器中的bean类
    @ConditionalOnMissingBean //条件判断，当没有这个bean的时候在创建
    public AliOssUtil aliOssUtil(AliOssProperties aliOssProperties){ //参数注入的方式
        log.info("开始创建阿里云工具类对象：{}",aliOssProperties);
        return new AliOssUtil(aliOssProperties.getEndpoint(),
                aliOssProperties.getAccessKeyId(),
                aliOssProperties.getAccessKeySecret(),
                aliOssProperties.getBucketName());
    }
}
